package gqz.mvvm.Test;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import gqz.mvvm.R;

/**
 * Created by Administrator on 2018/3/21.
 */

public class ActivityA extends Activity {

    Button btn;
    TextView tv;
    Handler handler = new Handler();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_a);

        tv = (TextView) findViewById(R.id.test_activitya_tv);
        btn = (Button) findViewById(R.id.test_activitya_btn_goB);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent();
                i.setClass(ActivityA.this, ActivityB.class);
                i.putExtra("data", "activity");
                startActivityForResult(i, 1);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1 && resultCode == Activity.RESULT_OK) {
            tv.setText("data=" + data.getStringExtra("data"));
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    tv.setText("");
                }
            },3000);
        }
    }
}
